package com.galo.service.service;

import com.alibaba.fastjson.JSON;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Component;

import java.util.LinkedHashMap;
import java.util.Map;

/**
 * 电动窗帘
 * @Auther: lxlin
 * @Date: 2018/11/16 13:09
 * @Description:
 */
@Component
public class ElectricCurtainService {

    @Autowired
    private MqttGateway gateway;

    /**
     * 电动窗帘控制接口
     * @param devsn 窗帘设备编号
     * @param target 开启程度 0：全关闭  100：全打开  （数值越大，打开程度越大）
     */
    @Async("taskExecutor")
    public void curtain(String devsn,int target){
        Map map = new LinkedHashMap();
        map.put("type","ele-ctn");
        map.put("action","set");
        map.put("devsn",devsn);
        map.put("target",target);
        gateway.sendToMqtt("galo/device/control/curtain",1, JSON.toJSONString(map));
    }
}
